package com.system.provider;

import com.am.ui.grid.AbstractBaseGridProvider;
import com.system.uitls.CommonUtil;
import com.system.uitls.SearchFilter;
import java.util.Map;

public class ApproveDetails extends AbstractBaseGridProvider
{
  public String generateSql(Map<String, Object> map)
  {
    String startTime = CommonUtil.nullToEmptyString(map.get("startTime"));
    String endTime = CommonUtil.nullToEmptyString(map.get("endTime"));
    String type = CommonUtil.nullToEmptyString(map.get("type"));

    StringBuffer sql = new StringBuffer("SELECT t4.name,t3.quantity,t3.type,t2.user_name,t2.create_time,t2.notes FROM sys_approve t1,sys_out_storage t2,sys_drug_history t3,sys_drug t4 WHERE t1.out_storage_id = t2.id AND t3.out_storage_id = t1.out_storage_id AND t4.id = t3.drug_id AND t1.id = :id AND t1.status = :status");

    if (!"".equals(startTime)) {
      sql.append(" AND t2.create_time>=:startTime");
    }

    if (!"".equals(endTime)) {
      sql.append(" AND t2.create_time<=:endTime");
    }

    if (!"".equals(type)) {
      sql.append(" AND t1.type=:type");
    }

    sql.append(SearchFilter.getSearchSql(map, null));
    setParamMap(map);
    return sql.toString();
  }
}